function [ Database ] = ResetDatabase(restore_epochs, restore_timefrequency, restore_tfc)
if ~exist('restore_epochs', 'var'); restore_epochs = false; end;
if ~exist('restore_timefrequency', 'var'); restore_timefrequency = false; end;

%% Make database global
global Database;
Database = [];

%% Filepaths
databasepath = getpref('ECoG', 'Data');
if isunix; sepa = '/'; else sepa = '\'; end;
Database.Path.Data = databasepath;
Database.Path.EEGLabData = [databasepath 'EEGLab' sepa];
Database.Path.TimeFrequencyData = [databasepath 'TimeFrequency' sepa];
Database.Path.TFCData = [databasepath 'TFC' sepa];
Database.Path.Results = getpref('ECoG', 'Results');
Database.Path.DatabaseStorage = [databasepath 'Database' sepa];

%% Subjects database
Db.subjects_header = {'Code', 'Name', 'Electrodes'}; 
Db.subjects = cell(0,3);
load([Database.Path.DatabaseStorage 'Electrodes.mat']); %#ok<NODEF>


sList = SubjectInfo.List;
for s = sList
    subj = cell2mat(s);
    subject = SubjectInfo.Load(subj);
    cCode = subject.PrimaryPrefix;
    cName = subject.Name;
    cElectrodes = Electrodes.(cCode);
%     for e = {subject.Electrodes.Label}
%         elec = cell2mat(e);
%         elecf = elec;
%         elecf(elecf=='+') = '_';
%         cElectrodes.(elecf) = elec;
%     end
    Db.subjects = [Db.subjects;{ cCode, cName, cElectrodes}];
%     Electrodes.(cCode) = cElectrodes;
end
% Make global..
Database.subjects_header = Db.subjects_header;
Database.subjects = Db.subjects;

%% Regions database
disp('Creating ''subjects'' and ''regions'' datatable..')
% Make sure that subjects database already exists!
UpdateRegionDatabase;

%% Update the filesystem data
disp('Creating datatables for various files.. <DISABLED>')
warning('RALPH:DisabledCode', 'UpdateFileDatabases is disabled!!');
%UpdateFileDatabases;

%% Conditions
disp('Creating ''conditions'' datatable..')
Database.conditions_header = {'Name', 'Code', 'Type'};
Database.conditions = {...
    'Sphere Ambiguous Response','SPAR','Response';...
    'Sphere Unambiguous Response','SPUR','Response';...
    'Sphere Unambiguous Stimulus','SPUS','Stimulus';...
    'Sphere Voluntary Stimulus','SVS','Stimulus';...
    'Sphere Voluntary Wanted Response','SVWR','Response';...
    'Sphere Voluntary Unwanted Response','SVUR','Response';...
    'FaceHouse Ambiguous Response','FHAR','Response';...
    'FaceHouse Ambiguous Face Response','FHAFR','Response';...
    'FaceHouse Ambiguous House Response','FHAHR','Response';...
    'FaceHouse Unambiguous Response','FHUR','Response';...
    'FaceHouse Unambiguous Face Response','FHUFR','Response';...
    'FaceHouse Unambiguous House Response','FHUHR','Response';...
    'FaceHouse Unambiguous Stimulus','FHUS','Stimulus';...
    'FaceHouse Unambiguous Face Stimulus','FHUFS','Stimulus';...
    'FaceHouse Unambiguous House Stimulus','FHUHS','Stimulus';...
    'Ambiguous Response', 'AMBR','Response';...
    'Unambiguous Response', 'UNAR','Response';...
    'Unambiguous Stimulus', 'UNAS','Stimulus' ...
    };

%% Epoch information
Database.epochs_header = {'Subject', 'Condition', 'Short', 'NrOfEpochs', 'Datecode', 'Configuration', 'Filename'};
Database.epochs = cell(0, size(Database.epochs_header,2));
if restore_epochs
    disp('Restoring ''epochs'' datatable..');
    RestoreEpochDataOutputDatabase; 
else
    disp('Creating ''epochs'' datatable..');
end

%% TimeFrequency files
Database.timefrequency_header = {'Filename', 'Subject', 'Channel', 'ChannelType', 'Condition', 'Frequencies', 'Times', 'NrOfEpochs'};
Database.timefrequency = cell(0, size(Database.timefrequency_header,2));
if restore_timefrequency
    disp('Restoring ''timefrequency'' datatable..');
    RestoreTimeFrequencyFilesDatabase;
else
    disp('Creating ''timefrequency'' datatable..');
end

%% TFC files
Database.tfc_header = {'Filename', 'Subjects', 'Conditions', 'FrequencyBins', 'BaselineSettings', 'Times'};
Database.tfc = cell(0, size(Database.tfc_header,2));
if restore_timefrequency
    disp('Restoring ''tfc'' datatable..');
    RestoreTFCFilesDatabase;
else
    disp('Creating ''tfc'' datatable..');
end


end

